Uptown
Simplify prototypical inheritance. This tries to provide some simple constructs for providing functionality you get with ES6 classes, such as:
- Constructor functions
- Static class methods
- Getter and setter methods
Install
npm install uptown --save
Usage
Use extendify
to add the extend method to a class (note: it mutates the original class).
The extend
class method takes three options arguments:
- Object of instance properites
- Object of static methods and properties
- Object of getter and setter mutators
var extendify = require('uptown').extendify;
var Original = function() {};
Original.prototype.hello = function(value) {
return 'Hello, ' + value;
}
extendify(Original);
var SubClass = Original.extend({
constructor: function() {
Original.apply(this, arguments);
},
hello: function(value) {
return Original.prototype.hello.call(this, value + '!')
}
}, {
staticMethod: function() {}
}, {
foo: {
get: function() {},
set: function() {}
}
});
New classes may also be created using the createClass
function. The createClass
function works just like .extend
.
var createClass = require('uptown').createClass;
var Foo = createClass({
constructor: function() {
this.foo = 'bar';
}
});